package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.entity.Baby;
import org.come.mouslisten.BabyTalentMouslisten;

import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class TestChildTalentJpanel extends JPanel {
    private BabyTalentMouslisten[] mouslistens = new BabyTalentMouslisten[9];
    private JLabel[] jLabels = new JLabel[9];

    public TestChildTalentJpanel() {
        if("水墨UI".equals(MyIsif.getStyle())) {
            this.setPreferredSize(new Dimension(240, 215));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);
            this.setLayout(null);
            for (int i = 0; i < 9; i++) {
                jLabels[i] = new JLabel();
                mouslistens[i] = new BabyTalentMouslisten(i);
                jLabels[i].addMouseListener(mouslistens[i]);
                if (i < 3) {
                    jLabels[i].setBounds(18 + 72 * i, 28, 54, 52);
                } else if (i < 6) {
                    jLabels[i].setBounds(37 + 72 * (i - 3), 88, 20, 45);
                } else {
                    jLabels[i].setBounds(26 + 73 * (i - 6), 143, 40, 40);
                }

                this.add(jLabels[i]);
            }
        }else{
            this.setPreferredSize(new Dimension(240, 214));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);
            this.setLayout(null);
            for (int i = 0; i < 9; i++) {
                jLabels[i] = new JLabel();
                mouslistens[i] = new BabyTalentMouslisten(i);
                jLabels[i].addMouseListener(mouslistens[i]);
                if (i < 3) {
                    jLabels[i].setBounds(16 + 72 * i, 24, 54, 52);
                } else if (i < 6) {
                    jLabels[i].setBounds(30 + 70 * (i - 3), 88, 20, 45);
                } else {
                    jLabels[i].setBounds(25 + 70 * (i - 6), 140, 40, 40);
                }

                this.add(jLabels[i]);
            }
        }
    }

    public void showBaby(Baby baby) {
        for (int i = 0; i < 9; i++) {
            jLabels[i].setIcon(null);
        }
        if (baby != null) {
            String Talents = baby.getTalents();
            if (Talents != null && !"".equals(Talents)) {
                String[] v = Talents.split("\\|");
                for (int i = 0; i < v.length; i++) {
                    String[] vs = v[i].split("=");
                    ImageIcon icon = getTalents(vs[0]);
                    Image img = icon.getImage().getScaledInstance(55, 55, Image.SCALE_DEFAULT);
                    jLabels[i].setIcon(new ImageIcon(img));
                    if (Integer.parseInt(vs[0]) > 3) {
                        img = icon.getImage().getScaledInstance(40, 40, Image.SCALE_DEFAULT);
                        jLabels[i + 6].setIcon(new ImageIcon(img));
                    }
                }
            }
        }
    }

    public ImageIcon getTalents(String id) {
        return new ImageIcon("inkImg/old/skill/" + id + ".png");
    }

    ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if("水墨UI".equals(MyIsif.getStyle())) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B218.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 240, 215, this);
        }else{
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/2/121_png.xy2uiimg.tz_bg.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 240, 214, this);
        }
    }
}
